package com.jieshen.lesson2;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ActionTwo {
    public static void main(String[] args) {
        // 两个按钮，实现同一监听
        //开始 停止
        Frame frame = new Frame("开始  停止");
        Button start = new Button("start");
        start.setActionCommand("启动");
        Button stop = new Button("stop");

        MyMonitor myMonitor = new MyMonitor();
        start.addActionListener(myMonitor);
        stop.addActionListener(myMonitor);
        frame.add(start,BorderLayout.NORTH);
        frame.add(stop,BorderLayout.SOUTH);
        frame.pack();
        frame.setVisible(true);
    }
}

class MyMonitor implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        String actionCommand = e.getActionCommand();
        if(actionCommand.equals("启动")){
            System.out.println("start被按下了");
        }else if(actionCommand.equals("stop")){
            System.out.println("stop被按下了");
        }
    }
}
